import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * Created With IntelliJ IDEA
 * Description:牛客网:HJ43 迷宫问题
 * <a href="https://www.nowcoder.com/practice/cf24906056f4488c9ddb132f317e03bc?tpId=37&tqId=21266&ru=/exam/oj">...</a>
 * User: DELL
 * Data: 2023-04-16
 * Time: 11:50
 */
public class Main {
    private static class Node {
        int row = 0;
        int col = 0;
        public Node(int row, int col) {
            this.row = row;
            this.col = col;
        }
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int row = scanner.nextInt();
        int col = scanner.nextInt();
        int[][] board = new int[row][col];
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                board[i][j] = scanner.nextInt();
            }
        }
        Deque<Node> res = new LinkedList<>();
        dfs (board,res,0,0);
        for (Node node : res) {
            System.out.println("(" + node.row + "," + node.col + ")");
        }
    }

    private static boolean dfs(int[][] board, Deque<Node> res, int curRow, int curCol) {
        //将该路径结点添加进去
        res.add(new Node(curRow,curCol));
        //如果已经到达右下角就返回
        if (curRow == board.length-1 && curCol == board[0].length-1) {
            return true;
        }
        //将本结点改为“墙”，即避免往回走
        board[curRow][curCol] = 1;
        //往上边走
        if (curRow > 0 && board[curRow-1][curCol] == 0) {
            if (dfs(board,res,curRow-1,curCol)) {
                return true;
            }
        }
        //往下边走
        if (curRow < board.length-1 && board[curRow+1][curCol] == 0) {
            if (dfs(board,res,curRow+1,curCol)) {
                return true;
            }
        }
        //往左边走
        if (curCol > 0 && board[curRow][curCol-1] == 0) {
            if (dfs(board,res,curRow,curCol-1)) {
                return true;
            }
        }
        //往右边走
        if (curCol < board[0].length-1 && board[curRow][curCol+1] == 0) {
            if (dfs(board,res,curRow,curCol+1)) {
                return true;
            }
        }
        //改回原样
        board[curRow][curCol] = 0;
        res.removeLast();
        return false;
    }
}
